<?php

namespace app\common\model;

class MallOrder extends Base
{
    protected $deleteTime = 'delete_time';


    /**
     * @param string $order_id
     * @return MallOrder|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOrderByOrderId(string $order_id = "")
    {
        return $this->where('order_sn', $order_id)
            ->find();
    }

    /**
     * @param array $where
     * @param string $field
     * @return MallOrder|array|mixed|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getOrderByOrderFind(array $where = [], string $field = '*')
    {
        return $this->field($field)
            ->where($where)
            ->find();
    }

    public function machine()
    {
        return $this->hasOne(MachineMachine::class, 'machine_id', 'machine_id');
    }

    public function cate()
    {
        return $this->hasOne(MachineCate::class, 'id', 'cate_id');
    }
    public function wechat(){
        return $this->hasOne(WeixinUser::class, 'openid', 'openid');
    }
}